﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QLNHDAO;

namespace QLNHBUS
{
    public class SanPhamBUS
    {
        public static List<object> LayDanhSachSanPhamChuaXoa(int id)
        {
            SanPhamDAO spDAO = new SanPhamDAO();
            var result = spDAO.SearchFor(c => (c.NhomSanPham.MaNhomSanPham == id && c.Xoa == false)).ToList();

            var filter = from sp in result
                         select new { sp.MaSanPham, sp.Ten, sp.KhoiLuong, sp.NguonCungCap, sp.HangDung, sp.GiaHienHanh, NhomSanPham = sp.NhomSanPham.Ten, Kho = sp.Kho.Ten};
            return filter.ToList<object>();
        }

        public static void ThemSanPham(SanPham sanpham)
        {
            SanPhamDAO spDAO = new SanPhamDAO();
            spDAO.Add(sanpham);
        }

        public static void CapNhatSanPham(SanPham sanpham)
        {
            SanPhamDAO spDAO = new SanPhamDAO();
            spDAO.Update(sanpham);
        }

        public static string TestThemSP()
        {
            try
            {
                SanPhamDAO spDAO = new SanPhamDAO();
                SanPham sanpham = new SanPham();
                sanpham.Ten = "test";
                sanpham.NhomSanPham = NhomSanPhamBUS.LayNhomSanPham(1);
                spDAO.Add(sanpham);
                return "true";
            }
            catch (Exception)
            {
                return "false";
            }
        }
    }
}
